#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
int cmp(int* e1, int* e2) {
	return *e1 - *e2;
}
void test()
{
    int arr[4];
    int nums[] = { -18,12,3,0 };
    int target = -6;
    memcpy(arr, nums, sizeof(int) * 4);
    qsort(nums, 4, 4, cmp);
    int l = 0;
    int r = 4 - 1;
    int* ans = (int*)calloc(2, 4);
    while (l <= r)
    {
        int sum = nums[l] + nums[r];
        if (sum > target)
        {
            --r;
        }
        else if (sum < target)
        {
            ++l;
        }
        else
        {
            ans[0] = nums[l];
            ans[1] = nums[r];
            break;
        }
    }
    for (int i = 0; i < 4; ++i)
    {
        if (arr[i] == ans[0])
        {
            ans[0] = i;
        }
        else if (arr[i] == ans[1])
        {
            ans[1] = i;
        }
    }
}
int main()
{
	test();
	return 0;
}